<cfparam default="0" name="url.action">
<cfparam default="0" name="url.start">
<cfparam default="0" name="url.end">
<cfparam default="0" name="url.search_term_1">
<cfparam default="0" name="url.search_term_2">
<cfparam default="0" name="url.search_term_3">
<cfparam default="0" name="url.search_term_4">
<cfparam default="0" name="url.search_term_5">
<cfparam default="0" name="url.search_term_6">
<cfparam default="0" name="url.search_term_7">
<cfparam default="0" name="url.sort_column">
<cfparam default="0" name="url.sort_direction">
<cfparam default="0" name="url.category">

<cfcontent reset="yes">
<cfinvoke component="components.data" method="category" returnvariable="categorys">
<cfinvoke component="components.data" method="five_star_area_category" returnvariable="area">
<cfinvoke component="components.data" method="expertise" returnvariable="expertise">

<cfif url.start neq "" and url.end neq "" >
<cfset __start__ = '
availability_start >= ##' & dateformat(url.start,"mm/dd/yyyy") & '## AND availability_end <= ##' & dateformat(url.end,"mm/dd/yyyy") & '## OR availability_start <= ##' & dateformat(url.start,"mm/dd/yyyy") & '## AND availability_end >= ##' & dateformat(url.end,"mm/dd/yyyy") & '## OR availability_start <= ##' & dateformat(url.start,"mm/dd/yyyy") & '## AND availability_end >= ##' & dateformat(url.start,"mm/dd/yyyy") & '## OR availability_start <= ##' & dateformat(url.end,"mm/dd/yyyy") & '##  AND availability_end >= ##' & dateformat(url.end,"mm/dd/yyyy") & '##'>
</cfif>
<cfquery datasource="#session.dsn#" name="search_results" >
select * 
from poc_detail
WHERE 
<cfif url.search_term_1 neq "not_selected">
poc_type = '#url.search_term_1#' AND 
</cfif>
<cfif url.search_term_2 neq "not_selected">
gov_type = '#url.search_term_2#' AND
</cfif>
<cfif url.search_term_3 neq "not_selected">
discipline = '#url.search_term_3#' AND
</cfif>
<cfif url.search_term_4 neq "">
first_name like '%#url.search_term_4#%' or
last_name like '%#url.search_term_4#%' AND 
</cfif>
<cfif url.search_term_5 neq "not_selected">
company ='#url.search_term_5#' AND 
</cfif>
<cfif url.search_term_6 neq "">
<cfloop to="#listlen(url.search_term_6,'_')#" from="1" index="i">
state = '#listgetat(url.search_term_6,i,'_')#' OR
</cfloop>
1=0 AND
</cfif>
<cfif url.search_term_7 neq "not_selected">
five_star_area ='#url.search_term_7#' AND
</cfif>
<cfif url.category neq "not_selected">
five_star_category like '%#url.category#%' AND 
</cfif>
<cfif url.start neq "" and url.end neq "" >
#__start__#
AND
</cfif>

1 = 1
ORDER BY #url.sort_column# #url.sort_direction#
</cfquery>

<cfswitch expression="#url.action#">

<cfcase value="get_first">

<cfset lowest_limit = 1>
<cfset highest_limit = 10>

</cfcase>

<cfcase value="get_previous">

<cfset highest_limit = lowest_term - 1>
<cfset lowest_limit = highest_limit - 9>
<cfif lowest_limit LT 1>
	<cfset lowest_limit = 1>
	<cfset highest_limit = 10>
</cfif>

</cfcase>

<cfcase value="get_next">

<cfset lowest_limit = highest_term + 1>
<cfset highest_limit = lowest_limit + 9>
<cfif highest_limit GT search_results.RecordCount>
	<cfset lowest_limit = search_results.RecordCount - 9>
	<cfset highest_limit = search_results.RecordCount>
</cfif>

</cfcase>

<cfcase value="get_last">

<cfset lowest_limit = search_results.RecordCount - 9>
<cfset highest_limit = search_results.RecordCount>

</cfcase>

</cfswitch>

<cfif search_results.RecordCount NEQ 0>
	<cfset lowest_result = search_results.RecordCount>
	<cfset highest_result = 1>
	<cfset result_message = ''>
	<cfset result_message = '{"result":['>
	<cfloop query="search_results">
		<cfif search_results.CurrentRow GTE lowest_limit AND search_results.CurrentRow LTE highest_limit>		
		
			<cfset result_message =  result_message & '{"poc_id":"' & search_results.poc_id & '","column_first_name":"' & Session.helpers.add_json_escapement(search_results.first_name) & '","column_last_name":"'>
			<cfset result_message = result_message & Session.helpers.add_json_escapement(search_results.last_name)>			
			<cfset result_message =  result_message & '","column_email":"'>		
			<cfset result_message = result_message & Session.helpers.add_json_escapement(search_results.email)>
			<cfset result_message =  result_message & '","column_address":"'>		
			<cfset result_message = result_message & Session.helpers.add_json_escapement(JSStringFormat(search_results.address))>
			<cfset result_message =  result_message & '","column_city":"'>		
			<cfset result_message = result_message & Session.helpers.add_json_escapement(search_results.city)>
			<cfset result_message =  result_message & '","column_state":"'>		
			<cfset result_message = result_message & Session.helpers.add_json_escapement(search_results.state)>
			<cfset result_message =  result_message & '","column_zip":"'>		
			<cfset result_message = result_message & Session.helpers.add_json_escapement(search_results.zip)>
			<cfset result_message =  result_message & '","column_phone":"'>		
			<cfset result_message = result_message & Session.helpers.add_json_escapement(search_results.phone)>
			<cfset result_message =  result_message & '","column_alt_phone":"'>		
			<cfset result_message = result_message & Session.helpers.add_json_escapement(search_results.alt_phone)>
			<cfset result_message =  result_message & '","column_alt_email":"'>		
			<cfset result_message = result_message & Session.helpers.add_json_escapement(search_results.alt_email)>
			<cfset result_message =  result_message & '","column_five_star_area":"'>		
			<cfset result_message = result_message & Session.helpers.add_json_escapement(search_results.five_star_area)>
			<cfset result_message =  result_message & '","column_five_star_category":"'>		
			<cfset result_message = result_message & Session.helpers.add_json_escapement(search_results.five_star_category)>
			<cfset result_message =  result_message & '","column_overall_level_of_expertise":"'>		
			<cfset result_message = result_message & Session.helpers.add_json_escapement(search_results.overall_level_of_expertise)>
			<cfset result_message =  result_message & '","column_company":"'>
			<cfset result_message = result_message & Session.helpers.add_json_escapement(search_results.company)>
			<cfset result_message =  result_message & '","column_certification":"'>		
			<cfset result_message = result_message & Session.helpers.add_json_escapement(search_results.certification)>
			<cfset result_message =  result_message & '","column_yrs_five_star_area_experience":"'>		
			<cfset result_message = result_message & Session.helpers.add_json_escapement(search_results.yrs_five_star_area_experience)>
			<cfset result_message =  result_message & '","column_yrs_category_experience":"'>		
			<cfset result_message = result_message & Session.helpers.add_json_escapement(search_results.yrs_category_experience)>
			<cfset result_message =  result_message & '","column_availability_start":"'>		
			<cfset result_message = result_message & Session.helpers.add_json_escapement(search_results.availability_start)>
			<cfset result_message =  result_message & '","column_availability_end":"'>		
			<cfset result_message = result_message & Session.helpers.add_json_escapement(search_results.availability_end)>
			<cfset result_message =  result_message & '","column_title":"'>		
			<cfset result_message = result_message & Session.helpers.add_json_escapement(search_results.title)>
			<cfset result_message =  result_message & '","column_work_load":"'>		
			<cfset result_message = result_message & Session.helpers.add_json_escapement(search_results.work_load)>
			<cfset result_message =  result_message & '","poc_type":"'>		
			<cfset result_message = result_message & Session.helpers.add_json_escapement(search_results.poc_type)>
			<cfset result_message =  result_message & '","column_comments":"'>		
			<cfset result_message = result_message & Session.helpers.add_json_escapement(search_results.comments)>
			<cfset result_message =  result_message & '","column_job_title":"'>		
			<cfset result_message = result_message & Session.helpers.add_json_escapement(search_results.job_title)>
			<cfset result_message =  result_message & '","column_status":"'>		
			<cfset result_message = result_message & Session.helpers.add_json_escapement(search_results.status)>
			<cfset result_message =  result_message & '","column_gov_type":"'>		
			<cfset result_message = result_message & Session.helpers.add_json_escapement(search_results.gov_type)>
			<cfset result_message =  result_message & '","column_discipline":"'>		
			<cfset result_message = result_message & Session.helpers.add_json_escapement(search_results.discipline)>
			<cfset result_message =  result_message & '","admin_email":"'>		
			<cfset result_message = result_message & Session.helpers.add_json_escapement(session.email)>
			<cfset result_message =  result_message & '","poc_comments":"'>		
			<cfset result_message = result_message & Session.helpers.add_json_escapement(search_results.comments)>			
			<cfset result_message = result_message & '"},'>
			<cfif search_results.CurrentRow LT lowest_result>
				<cfset lowest_result = search_results.CurrentRow>
			</cfif>
			<cfif search_results.CurrentRow GT highest_result>
				<cfset highest_result = search_results.CurrentRow>
			</cfif>
		</cfif>
	</cfloop>
	<cfset result_message = Session.helpers.remove_comma_from_end_of_string(result_message)>
	<cfset result_message = result_message & '],'>
	<cfset result_message = result_message & '"search_info":[{"lowest":"' & lowest_result & '","highest":"' & highest_result & '","search_term":"' & '","count":"' & search_results.RecordCount & '"}]}'>
	<cfcontent type="text/html" reset="yes">	<cfoutput>#result_message#</cfoutput>
<cfelse>
</cfif>